﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace ArkEC.CoreCom.Datastruct
{
    /// <summary>
    /// Ajax请求中的数据源结构
    /// </summary>
    public class AjaxTableStruct
    {
        /// <summary>
        /// 数据列表总数
        /// </summary>
        public int TotalCount;

        /// <summary>
        /// 数据列
        /// </summary>
        public List<string> TableColumns = new List<string>();

        /// <summary>
        /// 数据行
        /// </summary>
        public List<List<string>> Rows = new List<List<string>>();

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="dt"></param>
        public AjaxTableStruct(DataTable dt)
        {
            foreach (DataColumn column in dt.Columns)
            {
                this.TableColumns.Add(column.ColumnName);
            }

            foreach (DataRow row in dt.Rows)
            {
                List<string> cellValues = new List<string>();
                foreach (DataColumn column in dt.Columns)
                {
                    cellValues.Add(ObjectConvertion.DbToString(row[column]));
                }

                this.Rows.Add(cellValues);
            }
        }
    }
}
